#ifndef _CAN_H_
#define _CAN_H_


#include "sn_config.h"
typedef enum { 
    CAN_MSG_OK=0x00,
    CAN_MSG_CMDNUM_ERR=0x02,
    CAN_MSG_DATA_ERR=0x03,
    CAN_MSG_ADDR_ERR=0x04,
    CAN_MSG_RUN_ERR=0x07
}can_msg_error_t;

typedef enum {
    CAN_MSG_VER_A=0xA,
    CAN_MSG_VER_B=0xB,
}can_msg_ver_t;

struct can_msg_ext_id_t 
{
    can_msg_error_t err ;
    can_msg_ver_t  ver;
    uint8_t cmd;
    uint8_t  master_addr;
    uint32_t slave_addr;
};

struct can_obj_t
{
    uint32_t slave_addr;//源地址 本机地址
    uint8_t master_addr;//目标地址，远端地址
	  uint32_t rx_id;
    uint32_t tx_id;
    uint8_t err_num;
    uint8_t dev_num;
    uint8_t cmd_num;
		uint8_t ide;
		uint8_t rtr;
		uint8_t TX[8];
		uint8_t RX[8];
		uint8_t rx_sta;
};
struct can_dev_t
{

    uint8_t rx_flag;//接收标志
    uint8_t tx_flag;//发送标志
    uint8_t running_flag;//运行标志
	  struct can_obj_t obj;
    /**
     * @brief 接收完成
     * 
     */
    uint8_t (*rx_finish)(struct can_dev_t *dev);
    int (*tx_msg_func)(struct can_dev_t *dev,uint8_t *buf,uint8_t len);
    int (*rx_msg_func)(struct can_dev_t *dev);
    int (*set_ide)(struct can_dev_t *dev,uint8_t val);
    int (*set_rtr)(struct can_dev_t *dev,uint8_t val);
    int (*set_dst_id)(struct can_dev_t *dev,uint32_t val);
    int (*set_src_id)(struct can_dev_t *dev,uint32_t val);
    uint8_t (*check_running)(struct can_dev_t *dev);
    void (*can_clear_running_callback)(struct can_dev_t *dev);
	  void (*probe_master)(struct can_dev_t *dev);
};
struct can_dev_t * can_get_instance(void);
int can_init(struct can_dev_t **dev);
#endif // !_CAN_H_
